﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using hcom;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;

namespace hcms.Admin
{
	public partial class UserEdit : System.Web.UI.Page
	{
		protected string submitstate;	// 提示语
		protected string userid;	// 用户id。
		private hString hstr = new hString();
		private Model model = Global.model;
		protected void Page_Load(object sender, EventArgs e)
		{
			userid = Request["uid"];
			
			if (IsPostBack)
			{
				switch (cmd.Value)
				{
					case "save":
						save();
						break;
					default:
						throw (new Exception("不可识别的命令: \"" + cmd.Value + "\""));
				}
			}

			DataRow row			= model.getUserByID(userid);
			idid.InnerText		= row["userID"].ToString();
			idusername.Value	= row["userName"].ToString();
			idemail.Value		= row["userMail"].ToString();
			idpassword.Value	= row["userPassword"].ToString();
			idroles.Value		= row["userRoles"].ToString();
			iddate.InnerText	= row["userDate"].ToString();
			idip.InnerText		= row["userIP"].ToString();
		}

		private void save()
		{
			string strsql = string.Format("UPDATE hcms_Users SET userName='{0}'" +
				", userMail='{1}'" +
				", userPassword='{2}'" +
				", userRoles='{3}'" +
				" WHERE userID = '{4}'",
				hstr.ToSQL(idusername.Value),
				idemail.Value,
				hstr.ToSQL(idpassword.Value),
				hstr.ToSQL(idroles.Value),
				userid
				);
			model.da.Execute(strsql);

			submitstate = "保存完毕";
		}


	}
}